import { Controller, Get, Post, Body,Req, Patch, Param, Delete,UseGuards,UseInterceptors,ClassSerializerInterceptor } from '@nestjs/common';
import { AuthService } from './auth.service';
import { CreateAuthDto } from './dto/create-auth.dto';
import { AuthGuard } from '@nestjs/passport';
import { User } from 'src/system/user/entities/user.entity';
import {ApiTags, ApiOperation,ApiParam, ApiResponse } from '@nestjs/swagger';
import { Request } from 'express';
import { Public } from 'src/decorator/public';


@ApiTags('权限')
@Controller('auth')
export class AuthController {
  constructor(private readonly authService: AuthService) {}

  @UseGuards(AuthGuard('local'))
  @UseInterceptors(ClassSerializerInterceptor)
  @Post('login')
  @Public()
  @ApiOperation({ summary: '用户登录' })
  @ApiResponse({ status: 201, type: [User] })
  login(@Body() createAuthDto: CreateAuthDto,@Req() request:Request) {
    return this.authService.login(createAuthDto,request);
  }

  @ApiOperation({ summary: '用户登出' })
  @Get('logout')
  logout(@Req() request:Request) {
    return this.authService.logout(request)
  }

  @ApiOperation({ summary: '缓存列表' })
  @Get('redisKeys')
  getRedisKey() {
    return this.authService.getRedisKey()
  }
}
